package com.bree.erp.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQuery;

@NamedQuery(
		name=PrefixSequence.HQL_COUNT_PREFIX, 
		query= "SELECT count(1) FROM PrefixSequence p WHERE p.id <= :id and p.prefix = :prefix")
@Entity
public class PrefixSequence implements Serializable {

	private static final long serialVersionUID = 1L;

	public static final String HQL_COUNT_PREFIX = "countPrefixForSequenceValue";

	@Id @GeneratedValue(strategy=GenerationType.SEQUENCE)
	private Long id;
	
	@Column(length = 25)
	private String prefix;
	private Long sequence;
	
	@Override
	public String toString() {
		return prefix + String.format("%04d", sequence);
	}
	
	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}
	/**
	 * @return the prefix
	 */
	public String getPrefix() {
		return prefix;
	}
	/**
	 * @param prefix the prefix to set
	 */
	public void setPrefix(String prefix) {
		this.prefix = prefix;
	}
	/**
	 * @return the sequence
	 */
	public Long getSequence() {
		return sequence;
	}
	/**
	 * @param sequence the sequence to set
	 */
	public void setSequence(Long sequence) {
		this.sequence = sequence;
	}

}
